home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstrings.arc / RIGHT.C < prev    next >
Text File  |  1985-08-06  |  2KB  |  65 lines

  1. /*
  2.     CSTRINGS.LBR VERSION 1.0
  3.     Spark Software, Inc.
  4.  
  5.         If you find this software of use, it is requested that you send
  6.         a donation ($10.00 suggested) to:
  7.  
  8.             Spark Software, Inc.
  9.             24 Royal Crest Dr., #5
  10.             Nashua, NH  03060
  11.  
  12.         Upon receiving your donation, your name will be added to the 
  13.         List of Registered Users, and future updates can be obtained
  14.         from the SPARKIE RBBS at (603) 888-8179.
  15.  
  16.         If you include an extra $10.00 with your donation, the newest
  17.         version of CSTRINGS.LBR will be mailed to you.
  18.  
  19.         Call SPARKIE RBBS at the number above for other Spark Software
  20.         products!!!
  21. */
  22.  
  23. /*
  24.  *    char *
  25.  *    right (dest, str, n)
  26.  *    char *dest, *str;
  27.  *    int n;
  28.  *
  29.  *    This function returns a pointer to a string  (dest) containing the
  30.  *    rightmost n characters from str.  Note that it is assumed that
  31.  *    dest will be large enought to hold the entire result.
  32.  *    Note that the external declaration is necessary for some compilers
  33.  *    (including Lattice C large model) that have different sizes for
  34.  *      int's and char *'s.
  35.  */
  36.  
  37. char *right (dest, str, n)
  38. register char *dest, *str;
  39. register int n;
  40. {
  41.     extern char *strcpy ();
  42.     int str_size;
  43.  
  44.  
  45.                     /* First determine the length of str
  46.                        and save it since we will need
  47.                        it at least once more, and
  48.                        possibly twice more */
  49.     str_size = strlen (str);
  50.  
  51.                     /* Now copy the characters into the
  52.                        new string.    Notice that we do
  53.                        strcpy starting at  the strlen (str)
  54.                                            minus n 'th character.  The special
  55.                        case is when str is less than n
  56.                        characters, and we just copy the
  57.                        entire string */
  58.     dest = strcpy (dest,
  59.                  &str[(str_size > n) ? (str_size - n) : 0]);
  60.  
  61.                     /* Return the pointer to the result */
  62.     return (dest);
  63.  
  64. } /* right */
  65.